<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>拖车业务管理</title>
    <s:head/>
</head>
<script type="text/javascript">
    var formSetting = {
        title: "查询拖车业务信息",
        module: 'query',
        numCount: 4,
        columns: [{
            name: "businessId",
            label: "业务编号"
        }, {
            name: "trailState",
            label: "审核状态",
            type: "dropdown",
            dropdownType: "ajax",
            url: "../base/dropdown-trailState",
            op: "eq",
            minLength: 0
        }, {
            name: "pi",
            label: "PI号"
        }, {
            name: "so",
            label: "SO号"
        }, {
            name: "creator",
            label: "下单操作人"
        }, {
            name: "confirmTime",
            label: "业务提交时间从",
            type: "date",
            op: "ge"
        }, {
            name: "confirmTime",
            label: "到",
            type: "date",
            op: "le"
        }, {
            name: "supCompany.name",
            label: "供应商"
        }],
        buttons: {
            custom: [
                /* {
                 id : "updatebtn0",
                 value : "查看详细",
                 click : function() {
                 var id = $("#trailsDataGrid").jqGrid("getGridParam",
                 "selrow");
                 if(id) {
                 window.location.href="trail-bizView?id="+id+"&checkType=C";
                 // 							window.location.href="business-checkDetail?id="+id+"&singleType=C";
                 } else {
                 jw.alert("请点击需要操作的数据!");
                 }
                 }
                 }, */
// 				{
// 					id : "reject",
// 					value : "驳回",
// 					click : function() {
// 						var id = $("#trailsDataGrid").jqGrid("getGridParam","selrow");
// 						var rowDatas = $("#trailsDataGrid").jqGrid('getRowData',id);
// 						var row = rowDatas["trailState"];
// 						if(row == "草稿状态") {
// 							jw.dialog({
// 								iframe : '../business/rejectContent-reject?id='+id+"&type=2",
// 								title : "驳回",
// 								iframeFetchTitle : false,
// 								width : 600,
// 								height : 300
// 							});
// 						} else{
// 							jw.alert("请选择草稿状态业务的数据!");
// 						}
// 					}
// 				},
                /* {
                 id : "checkRejectContent",
                 value : "查看驳回",
                 click : function() {
                 var id = $("#trailsDataGrid").jqGrid("getGridParam",
                 "selrow");
                 var rowDatas = $("#trailsDataGrid").jqGrid('getRowData', id);
                 var row = rowDatas["trailState"];
                 if(row=="驳回状态" || row == "草稿状态") {
                 //window.location.href="rejectContent-rejectList?id="+id;
                 jw.dialog({iframe:'../business/rejectContent-rejectList?id='+id,title:"查看驳回",iframeFetchTitle:false, width:800, height:300});
                 } else {
                 jw.alert("请选择驳回状态业务的数据!");
                 }
                 }
                 }, */
                /* {
                 id : "updatebtn00",
                 value : "修改业务",
                 click : function() {
                 var id = $("#trailsDataGrid").jqGrid("getGridParam",
                 "selrow");
                 var rowDatas = $("#trailsDataGrid").jqGrid('getRowData',id);
                 var businessId = rowDatas["businessId"];
                 if(id) {
                 var ret = $("#trailsDataGrid").jqGrid('getRowData',id);
                 var data = "id=" + ret.id;
                 $.ajax({
                 url : "trail-checkBizModify",
                 dataType : "json",
                 data : data,
                 success : function(data) {
                 if($.parseJSON(data.msg).state==1) {
                 jw.confirm("确定要修改该业务?",function(){
                 window.location.href="business-updateSingle?id="+id+"&singleType=C&businessId="+businessId;
                 //jw.alert($.parseJSON(data.msg).msg);
                 //window.location.href="trail-bizModify?id="+ret.id;
                 },
                 function(){return;});
                 }
                 else if($.parseJSON(data.msg).state==0) {
                 jw.alert("只有处于草稿和驳回状态的业务才可以修改。");
                 }
                 else {
                 jw.alert($.parseJSON(data.msg).msg);
                 }
                 }
                 });
                 } else {
                 jw.alert("请点击需要操作的数据!");
                 }
                 }
                 }, */
                {
                    id: "delbtn",
                    value: "删除业务",
                    click: function () {
                        var selectedIds = $("#trailsDataGrid").jqGrid("getGridParam", "selrow");
                        var rowDatas = $("#trailsDataGrid").jqGrid('getRowData', selectedIds);
                        var row = rowDatas["trailState"];
                        if (row == "草稿状态") {
                            if (confirm("确定要删除选择的项?")) {
                                var data = "id=" + selectedIds;
                                $.ajax({
                                    url: "trail-del",
                                    dataType: "json",
                                    data: data,
                                    cache: false,
                                    success: function (data) {
                                        var msg = $.parseJSON(data.msg);
                                        if (msg.state == "1") {
                                            $("#trailsDataGrid").jqGrid("setGridParam",
                                                    {
                                                        search: true
                                                        // 将jqGrid的search选项设为true
                                                    }).trigger("reloadGrid", [{
                                                page: 1
                                            }]);
                                            jw.alert(msg.msg);
                                        } else {
                                            jw.alert(msg.msg);

                                        }
                                    }
                                });
                            }
                        } else {
                            jw.alert("请选择草稿状态业务的数据!");
                        }
                    }
                },
                {
                    id: "updatebtn1",
                    value: "提交业务",
                    click: function () {
                        var id = $("#trailsDataGrid").jqGrid("getGridParam",
                                "selrow");
                        if (id) {
                            var ret = $("#trailsDataGrid").jqGrid('getRowData', id);
// 								var iddata = "id=" + ret.id;
                            var iddata = "id=" + ret.id + "&sendMail=Y";
                            $.ajax({
                                url: "trail-checkBizConfirm",
                                dataType: "json",
                                data: iddata,
                                success: function (data) {
                                    if (!data) {
                                        return;
                                    }
                                    var msg = data.msg ? $.parseJSON(data.msg) : "";
                                    if (msg.state == 1) {
                                        jw.confirm("确定要提交该业务?", function () {
                                                    $.ajax({
                                                        url: "trail-bizConfirm",
                                                        dataType: "json",
                                                        data: iddata1,
                                                        success: function (data) {
                                                            jw.alert(msg.msg);
                                                            $("#trailsDataGrid").jqGrid("setGridParam",
                                                                    {
                                                                        search: true
                                                                        // 将jqGrid的search选项设为true
                                                                    }).trigger("reloadGrid", [{
                                                                page: 1
                                                            }]);
                                                        }
                                                    });
                                                },
                                                function () {
                                                    return;
                                                });
                                    }
                                else if (msg !== undefined && msg != "" && msg.state == 0) {
                                jw.alert("只有处于草稿和驳回状态的业务才可以提交。");
                                    }
                                    else {
                                        jw.alert(msg.msg);
                                    }
                                }
                            });
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                },
                {
                    id: "cancelbtn",
                    value: "取消订单申请",
                    click: function () {
                        var id = $("#trailsDataGrid").jqGrid("getGridParam",
                                "selrow");
                        if (id) {
                            var selectedIds = $("#trailsDataGrid").jqGrid("getGridParam", "selrow");
                            var rowDatas = $("#trailsDataGrid").jqGrid('getRowData', selectedIds);
                            var row = rowDatas["trailState"];
                            var businessId = rowDatas["businessId"];
                            if (row == "通过审核" || row == "安排中" || row == "已下单，待审核") {
                                jw.dialog({
                                    iframe: '../business/cancelReason-cancel?id=' + id + "&type=2&businessId=" + businessId,
                                    title: "取消订单",
                                    iframeFetchTitle: false,
                                    width: 600,
                                    height: 150
                                });
                            } else {
                                jw.alert("此状态订单不能取消!");
                            }
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                }
            ]
        },
        grid: {
            id: "trailsDataGrid",
            title: "查询结果",
            url: "trail-findList",
            //multiselect : true,
            /* postData : {
             "pid" : pid
             }, */
            colModel: [{
                index: "ID",
                name: "id",
                hidden: true
            }, {
                index: "pi",
                name: "pi",
                label: "PI号"
            }, {
                index: "businessId",
                name: "businessId",
                label: "业务编号"
            }, {
                index: "supNAME",
                name: "supCompany.name",
                label: "业务供应商"
            }, {
                index: "shipper",
                name: "shipper.company",
                label: "实际托运人",
                hidden: true
            }, {
                index: "confirmTime",
                name: "confirmTime",
                label: "业务提交时间",
                formatter: 'date',
                formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'}
            }, {
                index: "so",
                name: "so",
                label: "SO号"
            }, {
                index: "containerTotle",
                name: "containerTotle",
                label: "柜量"
            }, {
                index: "trailState",
                name: "trailState",
                label: "审核状态"
            }, {
                index: "operateState",
                name: "operateState",
                label: "业务操作进度",
                hidden: true
            }, {
                name: "creator",
                label: "下单操作人"
            }, {
                index: "trailStateVal",
                name: "trailState",
                label: "审核状态1",
                hidden: true
            }
                /* , {
                 index : "en",
                 name : "en",
                 label : "英文名"
                 }, {
                 index : "identifier",
                 name : "identifier",
                 label : "标识符"
                 }, {
                 index : "use_state",
                 name : "use_state",
                 label : "使用状态",
                 formatter : function(cellvalue, options, rowObject) {
                 if (cellvalue == "0") {
                 return "启用";
                 } else {
                 return "禁用";
                 }
                 }
                 }, {
                 index : "updateUser",
                 name : "updateUser",
                 label : "修改人"
                 }, {
                 index : "updateDate",
                 name : "updateDate",
                 label : "修改时间"
                 }  */],
            sortname: "businessId",
            sortorder: "desc",
            jsonReader: {
                root: "trails"
            },
            loadComplete: function (data) {
                var ids = $("#trailsDataGrid").getDataIDs();
                for (var i = 0; i < ids.length; i++) {
                    var arrayData = $("#trailsDataGrid").getRowData(ids[i]);
// 					if(arrayData.trailState == "已上传") {
                    if (arrayData.trailState == "安排中") {
// 						$("#trailsDataGrid").setCell(ids[i], "trailState", "安排中 <span style='cursor:pointer;' onclick=\"checkDetail(\'" + i + "\', 'state', \'"+arrayData.id+"\');\"><font color='red'>进度查询</font><span>");
                        $("#trailsDataGrid").setCell(ids[i], "trailState", "安排中 <span style='cursor:pointer;'><font color='red'>双击查看详细</font><span>");
                    } else if (arrayData.trailState == "已完成") {
                        $("#trailsDataGrid").setCell(ids[i], "trailState", "已完成  <span style='cursor:pointer;'><font color='red'>双击查看详细</font><span>");
                    } else if (arrayData.trailState == "通过审核") {
                        $("#trailsDataGrid").setCell(ids[i], "trailState", "通过审核 <span style='cursor:pointer;'><font color='red'>双击查看详细</font><span>");
                    } else if (arrayData.trailState == "驳回状态") {
                        $($("#" + arrayData.id).find("td")[7]).addClass("biz_state_reject");
                    } else {
// 						$("#trailsDataGrid").setCell(ids[i],"operateState","业务未上传");
// 						$("#trailsDataGrid").setCell(ids[i], "trailState", "草稿状态  <span style='cursor:pointer;'><font color='red'>双击进入修改业务</font><span>");
                    }
                }
            },
            ondblClickRow: function () {
                var selectedRowId = $("#trailsDataGrid").getGridParam("selrow");
                if (selectedRowId) {
                    var selectedRow = $("#trailsDataGrid").getRowData(selectedRowId);
                    if (selectedRow.trailState == "草稿状态") {
                        //selectedRow.busiId
                        location.href = "business-updateSingle?id=" + selectedRow.id + "&singleType=C";
                    } else {
// 						location.href = "business-updateSingle?id="+selectedRow.id+"&singleType=C&identification=list";
                        location.href = "trail-bizView?id=" + selectedRow.id + "&checkType=C";
                    }
                }
            }
        }
    };
    $(document).ready(function () {
        $("#trailsDataTable").mrdForm(formSetting);
    });

    function checkDetail() {
        var id = $("#trailsDataGrid").jqGrid("getGridParam",
                "selrow");
        if (id) {
            window.location.href = "trail-bizView?id=" + id;
//				window.location.href="business-checkDetail?id="+id+"&singleType=C";
        } else {
            jw.alert("请点击需要操作的数据!");
        }
    }

</script>
<body>
<div id="trailsDataTable"></div>
</body>
</html>
